﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Infrastructure.Helper
{
    public static class CommodityDataHelper
    {
        /// <summary>
        /// 解析SPU_DETAIL表的Detail字段，拿到商品的总表属性
        /// </summary>
        /// <param name="detail"></param>
        /// <returns></returns>
        public static Dictionary<string, string> SplitDetail(string detail)
        {
            var dic = new Dictionary<string, string>();
            try
            {
                foreach (var t in detail.Split(new string[] { "<li >", "<li>", "<Li >", "< li>" }, StringSplitOptions.RemoveEmptyEntries))
                {
                    string[] v = System.Text.RegularExpressions.Regex.Replace(t, @"<(.[^>]*)>", "", System.Text.RegularExpressions.RegexOptions.IgnoreCase).Replace("\n", "").Replace("\r", "").Replace("\t", "").Split('：');
                    if (v.Length <= 1)
                        v = t.Split(':');
                    if (v.Length > 1)
                    {
                        dic.Add(v[0], v[1]);
                    }
                }
                return dic;
            }
            catch (Exception)
            {
                return dic;
            }
        }
    }
}
